#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <error.h>
#include <unistd.h>

using namespace std;

int main()
{
    const char *filename = "./test1.txt";
    int fd1 = open(filename, O_RDWR | O_CREAT, 0644);
    if (fd1 == -1)
    {
        /* 打印错误原因 */
        perror("error:");
        // std::cout << "file open error" << std::endl;
    }
    cout << "fd1:" << fd1 << endl;

    filename = "./test2.txt";
    int fd2 = open(filename, O_RDWR | O_CREAT, 0644);
    if (fd2 == -1)
    {
        /* 打印错误原因 */
        perror("error:");
    }
    cout << "fd2:" << fd2 << endl;

    filename = "./test3.txt";
    int fd3 = open(filename, O_RDWR | O_CREAT, 0644);
    if (fd3 == -1)
    {
        /* 打印错误原因 */
        perror("error:");
    }
    cout << "fd3:" << fd3 << endl;

    /* 关闭文件 */
    close(fd1);
    close(fd2);
    close(fd3);
    
    while (1)
    {
        sleep(3);
    }
    return 0;
}